﻿#region File Description
//  XAEnima 
//  License: GNU/GPL
//  Developer: Federico Leonardo Motta
//  File description: This component handles the texts.
#endregion

#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
#endregion


namespace XAEnima.Core.GameManager
{
    public delegate void CharEventHandler();
    public class TextManager : Microsoft.Xna.Framework.GameComponent
    {
        String text;
        String buffer;
        Char character;
        KeyboardState kstate, oldstate;
        public TextManager(Game game)
            : base(game)
        {
        }

        public override void Update(GameTime gameTime)
        {
            /*  if ((oldstate.IsKeyUp(Keys.A)) && (kstate.IsKeyDown(Keys.A)) ){
                return "A";  
            }
            if ((oldstate.IsKeyUp(Keys.B)) && (kstate.IsKeyDown(Keys.B)) )
            {
                return "B";
            }
            if ((oldstate.IsKeyUp(Keys.C)) && (kstate.IsKeyDown(Keys.C)) )
            {
                return "C";
            }
            if ((oldstate.IsKeyUp(Keys.D)) && (kstate.IsKeyDown(Keys.D)))
            {
                return "D";
            }
            if ((oldstate.IsKeyUp(Keys.E)) && (kstate.IsKeyDown(Keys.E)) )
            {
                return "E";
            }
            if ((oldstate.IsKeyUp(Keys.F)) && (kstate.IsKeyDown(Keys.F)) )
            {
                return "F";
            }
            if ((oldstate.IsKeyUp(Keys.G)) && (kstate.IsKeyDown(Keys.G)) )
            {
                return "G";
            }
            if ((oldstate.IsKeyUp(Keys.H)) && (kstate.IsKeyDown(Keys.H)) )
            {
                return "H";
            }
            return null;*/
            kstate = Keyboard.GetState(PlayerIndex.One);
            if ((oldstate.IsKeyUp(Keys.A)) && (kstate.IsKeyDown(Keys.A)))
            {
                if (APressed != null) APressed();
            }
            if ((oldstate.IsKeyUp(Keys.B)) && (kstate.IsKeyDown(Keys.B)))
            {
                if (BPressed != null) BPressed();
            }
            if ((oldstate.IsKeyUp(Keys.C)) && (kstate.IsKeyDown(Keys.C)))
            {
                if (CPressed != null) CPressed();
            }
            if ((oldstate.IsKeyUp(Keys.D)) && (kstate.IsKeyDown(Keys.D)))
            {
                if (DPressed != null) DPressed();
            }
            if ((oldstate.IsKeyUp(Keys.E)) && (kstate.IsKeyDown(Keys.E)))
            {
                if (EPressed != null) EPressed();
            }
            if ((oldstate.IsKeyUp(Keys.F)) && (kstate.IsKeyDown(Keys.F)))
            {
                if (FPressed != null) FPressed();
            }
            if ((oldstate.IsKeyUp(Keys.G)) && (kstate.IsKeyDown(Keys.G)))
            {
                if (GPressed != null) GPressed();
            }
            if ((oldstate.IsKeyUp(Keys.H)) && (kstate.IsKeyDown(Keys.H)))
            {
                if (HPressed != null) HPressed();
            }
            if ((oldstate.IsKeyUp(Keys.I)) && (kstate.IsKeyDown(Keys.I)))
            {
                if (IPressed != null) IPressed();
            }
            if ((oldstate.IsKeyUp(Keys.L)) && (kstate.IsKeyDown(Keys.L)))
            {
                if (LPressed != null) LPressed();
            }
            if ((oldstate.IsKeyUp(Keys.M)) && (kstate.IsKeyDown(Keys.M)))
            {
                if (MPressed != null) MPressed();
            }
            if ((oldstate.IsKeyUp(Keys.N)) && (kstate.IsKeyDown(Keys.N)))
            {
                if (NPressed != null) NPressed();
            }
            if ((oldstate.IsKeyUp(Keys.O)) && (kstate.IsKeyDown(Keys.O)))
            {
                if (OPressed != null) OPressed();
            }
            if ((oldstate.IsKeyUp(Keys.P)) && (kstate.IsKeyDown(Keys.P)))
            {
                if (PPressed != null) PPressed();
            }
            if ((oldstate.IsKeyUp(Keys.Q)) && (kstate.IsKeyDown(Keys.Q)))
            {
                if (QPressed != null) QPressed();
            }
            if ((oldstate.IsKeyUp(Keys.R)) && (kstate.IsKeyDown(Keys.R)))
            {
                if (RPressed != null) RPressed();
            }
            if ((oldstate.IsKeyUp(Keys.S)) && (kstate.IsKeyDown(Keys.S)))
            {
                if (SPressed != null) SPressed();
            }
            if ((oldstate.IsKeyUp(Keys.T)) && (kstate.IsKeyDown(Keys.T)))
            {
                if (TPressed != null) TPressed();
            }
            if ((oldstate.IsKeyUp(Keys.U)) && (kstate.IsKeyDown(Keys.U)) ){
                if (UPressed != null) UPressed();
            }
            if ((oldstate.IsKeyUp(Keys.V)) && (kstate.IsKeyDown(Keys.V)) )
            {
                if (VPressed != null) VPressed();
            }
            if ((oldstate.IsKeyUp(Keys.Z)) && (kstate.IsKeyDown(Keys.Z)) )
            {
                if (ZPressed != null) ZPressed();
            }
            if ((oldstate.IsKeyUp(Keys.J)) && (kstate.IsKeyDown(Keys.J)) )
            {
                if (JPressed != null) JPressed();
            }
            if ((oldstate.IsKeyUp(Keys.K)) && (kstate.IsKeyDown(Keys.K)) )
            {
                if (KPressed != null) KPressed();
            }
            if ((oldstate.IsKeyUp(Keys.W)) && (kstate.IsKeyDown(Keys.W)))
            {
                if (WPressed != null) WPressed();
            }
            if ((oldstate.IsKeyUp(Keys.Y)) && (kstate.IsKeyDown(Keys.Y)))
            {
                if (YPressed != null) YPressed();
            }
            if ((oldstate.IsKeyUp(Keys.X)) && (kstate.IsKeyDown(Keys.X)) )
            {
                if (XPressed != null) XPressed();
            }
            if ((oldstate.IsKeyUp(Keys.D1)) && (kstate.IsKeyDown(Keys.D1)) )
            {
                if (Pressed1 != null) Pressed1();
            }
            if ((oldstate.IsKeyUp(Keys.D2)) && (kstate.IsKeyDown(Keys.D2)))
            {
                if (Pressed2 != null) Pressed2();
            }
            if ((oldstate.IsKeyUp(Keys.D3)) && (kstate.IsKeyDown(Keys.D3)))
            {
                if (Pressed3 != null) Pressed3();
            }
            if ((oldstate.IsKeyUp(Keys.D4)) && (kstate.IsKeyDown(Keys.D4)))
            {
                if (Pressed4 != null) Pressed4();
            }
            if ((oldstate.IsKeyUp(Keys.D5)) && (kstate.IsKeyDown(Keys.D5)))
            {
                if (Pressed5 != null) Pressed5();
            }
            if ((oldstate.IsKeyUp(Keys.D6)) && (kstate.IsKeyDown(Keys.D6)))
            {
                if (Pressed6 != null) Pressed6();
            }
            if ((oldstate.IsKeyUp(Keys.D7)) && (kstate.IsKeyDown(Keys.D7)))
            {
                if (Pressed7 != null) Pressed7();
            }
            if ((oldstate.IsKeyUp(Keys.D8)) && (kstate.IsKeyDown(Keys.D8)))
            {
                if (Pressed8 != null) Pressed8();
            }
            if ((oldstate.IsKeyUp(Keys.D9)) && (kstate.IsKeyDown(Keys.D9)))
            {
                if (Pressed9 != null) Pressed9();
            }
            if ((oldstate.IsKeyUp(Keys.D0)) && (kstate.IsKeyDown(Keys.D0)))
            {
                if (Pressed0 != null) Pressed0();
            }
            if ((oldstate.IsKeyUp(Keys.Space)) && (kstate.IsKeyDown(Keys.Space)))
            {
                if (SpacePressed != null) SpacePressed();
            }
            if ((oldstate.IsKeyUp(Keys.Back)) && (kstate.IsKeyDown(Keys.Back)))
            {
                if (BackPressed != null) BackPressed();
            }
            oldstate = kstate;
            base.Update(gameTime);
        }

        public event CharEventHandler APressed;
        public event CharEventHandler BPressed;
        public event CharEventHandler CPressed;
        public event CharEventHandler DPressed;
        public event CharEventHandler EPressed;
        public event CharEventHandler FPressed;
        public event CharEventHandler GPressed;
        public event CharEventHandler HPressed;
        public event CharEventHandler IPressed;
        public event CharEventHandler LPressed;
        public event CharEventHandler MPressed;
        public event CharEventHandler NPressed;
        public event CharEventHandler OPressed;
        public event CharEventHandler PPressed;
        public event CharEventHandler QPressed;
        public event CharEventHandler RPressed;
        public event CharEventHandler SPressed;
        public event CharEventHandler TPressed;
        public event CharEventHandler UPressed;
        public event CharEventHandler VPressed;
        public event CharEventHandler ZPressed;
        public event CharEventHandler WPressed;
        public event CharEventHandler JPressed;
        public event CharEventHandler KPressed;
        public event CharEventHandler XPressed;
        public event CharEventHandler YPressed;
        public event CharEventHandler Pressed1;
        public event CharEventHandler Pressed2;
        public event CharEventHandler Pressed3;
        public event CharEventHandler Pressed4;
        public event CharEventHandler Pressed5;
        public event CharEventHandler Pressed6;
        public event CharEventHandler Pressed7;
        public event CharEventHandler Pressed8;
        public event CharEventHandler Pressed9;
        public event CharEventHandler Pressed0;
        public event CharEventHandler SpacePressed;
        public event CharEventHandler BackPressed;

    }
}
